Repository navigation
feat(libc): implement the compiler-rt floating-point builtins - #6330
Merged
Merged
Conversation
Soft-float arithmetic and comparisons, float/double/x87 conversions to and from 32-, 64- and 128-bit integers, __extendsfdf2, __truncdfsf2, complex multiplication and division and __powixf2, matching the libc.prx bundled with PPSA08427: soft-float results ignore MXCSR and raise no flags, division flushes subnormal quotients, NaN payloads are moved unshifted and float-to-integer conversions do not saturate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q8tinbP1MUpUaDsbNWnGnu
Progress report (55d2fb6 → f8b611b)📈 System libraries: 88.91% (+0.2%, +66 implemented functions) ✅ 66 implemented
|
This was referenced Oct 15, 2026
Closed
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
11 tasks done
This was referenced Oct 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Implements the 66 compiler-rt floating-point builtins that the system
libc.prxexports and AnyPS5 did not have, in a newsrc/FloatBuiltins.cpp:__add,__sub,__mul,__div(sf3,df3),__neg{s,d}f2__eq,__ne,__lt,__le,__gt,__ge,__unord(sf2,df2)__extendsfdf2,__truncdfsf2__fix*,__fixuns*) and back (__float*,__floatun*)__mul{s,d,x}c3,__div{s,d,x}c3, and__powixf2The console ships an older compiler-rt built with FMA contraction, and these follow that binary (the
libc.prxbundled with PPSA08427) rather than current compiler-rt:__truncdfsf2always round to nearest, ignore FTZ/DAZ and raise no exception flags; here the SSE instruction runs under a default MXCSR that is restored afterwards (GNU inline asm, asMath.cppalready uses), and an invalid operation returns the positive quiet NaN compiler-rt returns instead of the SSE default NaN;__sub*negates the second operand first, like compiler-rt, so a NaN subtrahend comes back with its sign flipped__div{s,d}f3flush a quotient below the smallest normal to a signed zero (old compiler-rt's "Flush denormals to zero")__extendsfdf2keeps signalling NaNs and copies the payload unshifted;__truncdfsf2quiets and keeps the low 22 payload bits__floatsisf,__floatunsisfand the 128-bit sources round to nearest in integer code; the 64-bit sources use native conversions, which honour MXCSR like the console'scvtsi2s*fmaexactly where the console's code fuses, a NaN-skipping maximum like itsvmaxss/blend sequence, and scale through the x87 like itsscalbn(fscale)__powixf2(x, 1)returnsxunchangedRecorded in
docs/dev/debt/libc.md.Tested
Linux (CachyOS, GCC Release build, plus a clang
-Wall -Wextrasyntax check): newguest_float_builtinstest passes, as doguest_mathandguest_crt.tools/check_conventions.pypasses;tools/pr_overlap.py --branchreports no overlap.Differential test against the console: the
libc.prxof PPSA08427 was mapped into a Linux process (PT_LOAD segments, RELATIVE relocations, the stack-protector GOT slot pointed at a dummy guard) and each builtin was called side by side with this implementation on 200,000 random and edge-case inputs (NaNs with payloads, infinities, subnormals, boundary exponents), once with the default MXCSR and once with random rounding modes and FTZ/DAZ, comparing result bits and the MXCSR afterwards. All functions agree bit for bit, except:__mul{s,d}c3and__div{s,d}c3agree on every value but differ in about 2-6% of cases only in a NaN's payload/sign or in exception flags, because the hostfma/logbare not the console's VEX FMA code and libm; noted in the debt entry.__floatundidfcould not be run on Linux: it is compiler-rt's assembly with a legacy-SSEorpdon an 8-byte-aligned constant, which faults without AMD's misaligned-SSE mode. It is a correctly rounded conversion and is implemented as a native one.The harness is not part of this PR because it needs the console binary.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
https://claude.ai/code/session_01Q8tinbP1MUpUaDsbNWnGnu